function im = noiseonf(rows, cols, factor)

% f is the distance
% factor is alpha in f^factor 

im = randn(rows,cols); % noise picture
imfft = fft2(im); % Take fft of image.
imfft = fftshift(imfft); % Shift 0 frequency to the middle.
mag = abs(imfft);
phase = angle(imfft);
real = mag .* cos(phase);
imaginary = mag .* sin(phase);

filter = zeros(rows, cols);

for i = 1:rows
    for j = 1:cols
        x = floor(abs(round(j-((cols+1)/2))));
        y = floor(abs(round(i-((rows+1)/2))));
        f = sqrt( power(x,2) + power(y,2) );
        if f == 0
            f = 1;
        end
        filter(i,j) = 1/power(f, factor);
    end
end

newfft = (real + 1i .*imaginary);
im = abs(ifft2(fftshift(filter .*newfft))); % Invert to obtain final noise image
caption = sprintf('noise with 1/(f^{%2.1f}) amplitude spectrum',factor);
imagesc(im), axis('equal'), axis('off'), title(caption)
